<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Bike Sharing Analysis</title>
    <!-- Bootstrap CSS -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-KyZXEAg3QhqLMpG8r+Knujsl5/1z7ppgiIDocM58uhfypi8kD0rD7dpI1+YKW(8m" crossorigin="anonymous">
    <!-- Bootstrap JavaScript Bundle -->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js" integrity="sha384-cn7l7gDp0eyniUwwAZgrzD06kc/tftFf19TOAs2zVinnD/C7E91j9yyk5//jjpt/" crossorigin="anonymous"></script>
    <!-- jQuery -->
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>

    <style>
        body {
            background-color: #f8f9fa;
        }
        .card {
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
        }
        .container {
            max-width: 1200px;
        }
    </style>
</head>
<body>
<button id="reload-charts" class="btn btn-primary my-3">Reload Charts</button>

    <div class="container">
        <h1 class="my-5 text-center">Bike Sharing Analysis</h1>
        <div class="row">
            {% for chart in charts %}
                <div class="col-md-6 my-3">
                    <div class="card">
                        <div class="card-header bg-primary text-white">
                            <h2>{{ chart.name }}</h2>
                        </div>
                        <div class="card-body">
                            <img src="data:image/png;base64,{{ chart.data }}" alt="{{ chart.name }}" class="img-fluid">
                        </div>
                    </div>
                </div>
            {% endfor %}
        </div>
    </div>
</body>
<script>
    $(document).ready(function() {
        $("#reload-charts").click(function() {
            $.ajax({
                url: "/reload_charts",
                type: "GET",
                dataType: "json",
                success: function(response) {
                    $(".row").empty();
                    $.each(response.charts, function(index, chart) {
                        var chartDiv = `
                        <div class="col-md-6 my-3">
                            <div class="card">
                                <div class="card-header bg-primary text-white">
                                    <h2>${chart.name}</h2>
                                </div>
                                <div class="card-body">
                                    <img src="data:image/png;base64,${chart.data}" alt="${chart.name}" class="img-fluid">
                                </div>
                            </div>
                        </div>`;
                        $(".row").append(chartDiv);
                    });
                }
            });
        });
    });
</script>

</html>
